<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

    <script src="../../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
    <script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>

    <script src="../../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>


    <script src="../../../js/echarts.min.js"></script>
    <style>
        .weather {
            background: url(../../../images/bg.jpg) no-repeat;
            width: 250px;
            height: 88px;
            margin: 10px 2px 10px 6px;
            padding: 20px 2px 2px 65px;
        }
    </style>

</head>

<body>
    <blockquote class="layui-elem-quote layui-text">
        <!-- 天气 -->
        <div class="weather">
            <iframe width="200" scrolling="no" height="65" frameborder="0" allowtransparency="true"
                src="http://i.tianqi.com/index.php?c=code&id=12&icon=1&num=1">
            </iframe>
        </div>
    </blockquote>

    <fieldset class="table-search-fieldset">
        <legend>家居</legend>
        <div style="margin: 10px 10px 10px 10px">
            <form class="layui-form layui-form-pane" action="" id="fom1">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">家居名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="household_name" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">离职状态</label>
                        <div class="layui-input-inline">
                            <input type="text" name="serviceman_isdepar" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                            lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>


    <table class="layui-hide  lay-data=" id="househomeTable" lay-filter="househomeTable"></table>


    <script id="picTpl">
        <img src="{{d.serviceman_pic}}" name="serviceman_pic" style="width:100%; height:100%;" />

    </script>


    <script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
      <button class="layui-btn layui-btn-sm layui-btn-green" lay-event="householdadd">添加</button>
      <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="householdsdel">批量删除</button>
      <button class="layui-btn layui-btn-sm layui-btn-green" lay-event="echarts1">智能家居价格折线图</button>
      <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="outexcel">导出表格</button>
      <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="escelmodel">导入模板</button>

      <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="inexcel">导入表格</button>

      <!-- <button class="layui-btn layui-btn-sm" lay-event="isAll"></button> -->
    </div>
  </script>


    <script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  </script>


    <script type="text/javascript">
        //显示大图片
        function showBigImage(e) {
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                shadeClose: true, //点击阴影关闭
                area: [$(e).width + '%50', $(e).height + '%50'], //宽高
                area: ['80%', '80%'],
                content: "<img src=" + $(e).attr('src') + " />"
            });
        }
    </script>
    <script>


        layui.use('table', function () {
            var table = layui.table,
                $ = layui.jquery,
                form = layui.form;


            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                var result = JSON.stringify(data.field);
                if (data.field.serviceman_isdepar === "离职") {
                    data.field.serviceman_isdepar = 0;
                } else if (data.field.serviceman_isdepar === "正常") {
                    data.field.serviceman_isdepar = 1;
                }

                //执行搜索重载
                table.reload('househomeTable', {
                    page: {
                        curr: 1
                    }
                    , where: {
                        // 查询条件
                        household_name: data.field.household_name,
                        serviceman_isdepar: data.field.serviceman_isdepar
                    }
                }, 'data');

                return false;
            });


            table.render({
                elem: '#househomeTable'
                , url: 'http:///localhost:8080/household/householdList1'
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , title: '智能家居'
                , totalRow: true
                , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    , layEvent: 'LAYTABLE_TIPS'
                    , icon: 'layui-icon-tips'
                }]

                //   serviceman_name,serviceman_com,serviceman_tel,serviceman_pic,serviceman_isdepar
                , cols: [[
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'household_id', title: 'ID', align: "center", width: 80, fixed: 'left', unresize: true, sort: true }
                    , { field: 'household_name', title: '家居名称', align: "center", edit: 'text' }
                    , { field: 'household_price', title: '价格', align: "center", edit: 'text', sort: true }
                    , { field: 'household_lfdate', title: '出厂日期', align: "center", sort: true }
                    , { field: 'guarantee_id', align: "center", title: '保修单' }

                    , {
                        field: 'household_pic',
                        title: '家居照片',
                        templet: '<div><img src="{{d.household_pic}}" alt="" style="width:100%; height:100%;" onclick="showBigImage(this)""></div>'
                    }

                    , { field: 'serviceman_name', title: '保修工姓名', align: "center", edit: 'date', sort: true }
                    , { field: 'serviceman_com', title: '保修公司', align: "center", edit: 'text', sort: true }
                    , { field: 'serviceman_tel', title: '维修电话', align: "center", edit: 'text', sort: true }
                    // , { field: 'serviceman_pic', title: '维修证件照', align: "center", edit: 'text', templet: '#picTpl' }
                    // , {
                    //     field: 'serviceman_pic',
                    //     title: '家居照片',
                    //     templet: '<div><img src="{{d.serviceman_pic}}" alt="" style="width:100%; height:100%;" onclick="showBigImage(this)""></div>'
                    // }
                    , { field: 'serviceman_isdepar', title: '离职状态', align: "center", width: 100, edit: 'text' }


                    , { fixed: 'right', align: "center", title: '操作', toolbar: '#barDemo', width: 150 }

                ]]



                , page: true
                , response: {
                    statusCode: 0 //重新规定成功的状态码为 200，table 组件默认为 0
                }
                , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据

                    // debugger
                    for (var i = 0; i < res.data.households.length; i++) {
                        if (res.data.households[i].serviceman_isdepar == 1) {
                            res.data.households[i].serviceman_isdepar = "正常";

                        } else if (res.data.households[i].serviceman_isdepar == 0) {
                            res.data.households[i].serviceman_isdepar = "离职";

                        } else {
                            res.data.households[i].serviceman_isdepar = "请假";
                        }

                    }
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.message, //解析提示文本
                        "count": res.data.count, //解析数据长度
                        "data": res.data.households //解析数据列表
                    };
                }

            });





            //头工具栏事件
            table.on('toolbar(househomeTable)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {







                    // 添加
                    case 'householdadd':
                        {
                            var index = layer.open({
                                title: '添加家居',
                                type: 2,
                                shade: 0.2,
                                maxmin: true,
                                shadeClose: true,
                                area: ['80%', '80%'],
                                content: 'householdadd.html',
                                //列表重新加载
                                end: function (index) {
                                    table.reload('househomeTable');
                                }
                            });
                        };
                        $(window).on("resize", function () {
                            layer.full(index);
                        });
                        break;
                    // 批量删除
                    case 'householdsdel':
                        // 选中的数据
                        var data = checkStatus.data;
                        $.ajax({
                            type: "post",
                            url: "http://localhost:8080/household/househomesDel",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            dataType: "json",
                            success: function (res) {

                                if (res.code == 0) {
                                    layer.msg('删除成功', function () {

                                        table.reload('househomeTable');
                                        // 关闭弹出层
                                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(iframeIndex);
                                        layer.close(index)
                                        table.reload("#househomeTable")

                                    })

                                } else {
                                    layer.msg('删除失败', function () {

                                    });
                                }
                            }

                        })
                        break;


                    case 'echarts1':
                        {
                            var index = layer.open({
                                title: '智能家居价格折线图',
                                type: 2,
                                shade: 0.2,
                                maxmin: true,
                                shadeClose: true,
                                area: ['80%', '80%'],
                                content: 'echarts1.html',
                                //列表重新加载
                                end: function (index) {
                                    table.reload('househomeTable');
                                }
                            });
                        };
                        break;
                    case 'echarts2':
                        {
                            var index = layer.open({
                                title: '添加家居',
                                type: 2,
                                shade: 0.2,
                                maxmin: true,
                                shadeClose: true,
                                area: ['80%', '80%'],
                                content: 'householdadd.html',
                                //列表重新加载
                                end: function (index) {
                                    table.reload('househomeTable');
                                }
                            });
                        };

                        break;


                    //  导出表格
                    case 'outexcel':
                        {
                            // debugger
                            location.href = "http://localhost:8080/household/export?" + $("#fom1").serialize();
                        };
                        break;

                    //  导出模板
                    case 'escelmodel':
                        {
                            // debugger
                            location.href = "http://localhost:8080/household/escelModel";
                        };
                        break;


                    //导入表格 http://localhost:8080/household/import"

                    case 'inexcel':
                        {

                            var index = layer.open({
                                title: '导入表格',
                                type: 2,
                                shade: 0.2,
                                maxmin: true,
                                shadeClose: true,
                                area: ['80%', '80%'],
                                content: 'import.html',
                                //列表重新加载
                                end: function (index) {
                                    table.reload('househomeTable');
                                }
                            });
                        };
                        break;



                    case 'LAYTABLE_TIPS':
                        layer.alert('这是工具栏右侧自定义的一个图标按钮');
                        break;
                };


            });

            //监听行工具事件
            table.on('tool(househomeTable)', function (obj) {
                var data = obj.data;
                console.log(obj)
                // 将读取的一行数据存储到局部存储器
                var localhostStr = localStorage.setItem("localhostStr", JSON.stringify(data));

                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        obj.del();

                        $.ajax({
                            type: "post",
                            url: "http://localhost:8080/household/househomeDel",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            dataType: "json",
                            success: function (res) {

                                if (res.code == 0) {
                                    layer.msg('删除成功', function () {


                                        // 关闭弹出层
                                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(iframeIndex);
                                        layer.close(index)
                                        table.reload('househomeTable');

                                    })

                                } else {
                                    layer.msg('删除失败', function () {

                                    });
                                }
                            }

                        })



                        layer.close(index);
                    });



                } else if (obj.event === 'edit') {
                    var index = layer.open({
                        title: '编辑家居',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['100%', '100%'],
                        content: 'householdedit.html',
                        //列表重新加载
                        end: function (index) {
                            table.reload('househomeTable');
                        }

                    });

                    $(window).on("resize", function () {
                        layer.full(index);
                    });

                    return false;
                }
            });

        });

    </script>


</body>

</html>